<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class module extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct() {
		parent::__construct();
		ini_set('session.cookie_httponly',1); 
		ini_set('session.use_only_cookies',1);
		$this->load->model('module_class');
		$this->load->model('points_class');
	}	 
	public function get_list_module(){
		$data=array();
		
		$modules = $this->module_class->list_modules();
		if($modules!=0){
			foreach($modules as $key=>$value){
// 				$data['strName'][$key]=$value['strName'];			
// 				$data['strImgLink'][$key]=$value['strImgLink'];			
// 				$data['intOrderPanel'][$key]=$value['intOrderPanel'];			
// 				$data['intShowLogin'][$key]=$value['intShowLogin'];			
// 				$data['intOrderLogin'][$key]=$value['intOrderLogin'];			
// 				$data['strLink'][$key]=$value['strLink'];			
// 				$data['strLinkLogin'][$key]=$value['strLinkLogin'];			
// 				$data['strAltImgLink'][$key]=$value['strAltImgLink'];		
				$data['strName'][$key]=$value['strName'];
				$data['intShowPanel'][$key]=$value['intShowPanel'];
				$data['strImgLink'][$key]=$value['strImgLink'];
				$data['intOrderPanel'][$key]=$value['intOrderPanel'];
				$data['intShowLogin'][$key]=$value['intShowLogin'];
				$data['intOrderLogin'][$key]=$value['intOrderLogin'];
				$data['strLink'][$key]=$value['strLink'];
				$data['strLinkLogin'][$key]=$value['strLinkLogin'];
				$data['strAltImgLink'][$key]=$value['strAltImgLink'];
				$data['intBackend'][$key]=$value['intBackend'];	// Admin Dashboard Edited By Mark
				$data['strBackendLink'][$key]=$value['strBackendLink'];	// Admin Dashboard Edited By Mark	
			}
		}
		echo json_encode($data);
	}
	public function send_share_email(){
		$post = $this->input->post();
		$strName = $post['strName'];
		$strCCTO = $post['strEmail'];
		$strLink = "
Visit my Journey using this apps: http://www.facebook.com/TestJtn/app_190322544333196

Thanks,
$strName";
		$strAdminEmail = $this->session->userdata('strAdminEmail');
		$strAdminEmailName = $this->session->userdata('strAdminEmailName');
		$strSentPasswordEmail =$this->session->userdata('strSentPasswordEmail');
	
		$message_data = str_replace('$strName',$strName,$strLink);
		//$message_data = str_replace('$strPassword',$strPassword,$message_data);
		$message_data = str_replace('$strAdminEmailName',$strAdminEmailName,$message_data);
		$email_message = $message_data;
	
		$config['charset'] = 'utf-8';
		//$config['wordwrap'] = TRUE;
		//$config['mailtype'] = 'html';
		//$config['protocol'] = 'sendmail';
		$config['protocol'] = 'mail';
			
		$this->load->library('email',$config);
		$this->email->from($strAdminEmail, $strAdminEmailName);
		$this->email->to('');
		$this->email->cc($strCCTO);
		$this->email->bcc('');
	
		$this->email->subject('[Invite from Journey to 9 - '.date("M d, Y").']');
		$this->email->message($email_message);
	
		$this->email->send();
		$debug =  $this->email->print_debugger();
		$data['debug'] = $debug;
		$succes = "successfully sent";
		$pos = strpos($debug, $succes);
		if ($pos === false) {
			$data['email'] = 0;
		} else {
			$data['email'] = 1;
		}
	
		echo json_encode($data);
	}
	public function update_points_via_share(){
		$post = $this->input->post();
		$a = @split('%3D', @base64_decode($post['intID']));
		if($a[0]=='user_id'){
			$post['intID'] = $a['1'];
		}
		$message = '';
		$points = $this->points_class->get_points_via_share($post);
		if($points!=0){
			$message = $this->points_class->update_points_via_share($post);
		}
		echo json_encode($message);
	}
	public function update_available_points(){
		$post = $this->input->post();
		$a = @split('%3D', @base64_decode($post['intID']));
		if($a[0]=='user_id'){
			$post['intID'] = $a['1'];
		}
		$message = '';
		$points = $this->points_class->get_available_points($post);
		if($points!=0){
			$message = $this->points_class->update_available_points($post);
		}
		echo json_encode($message);
	}
	public function get_available_points(){
		$post = $this->input->post();
		$a = @split('%3D', @base64_decode($post['intID']));
		if($a[0]=='user_id'){
			$post['intID'] = $a['1'];
		}
		$getPoints = $this->points_class->get_available_points($post);
		if($getPoints!=0){
			$data['intPoints']=$getPoints['intPoints'];
		}
		echo json_encode($data);
	}
	public function get_points_via_share(){
		$post = $this->input->post();
		$a = @split('%3D', @base64_decode($post['intID']));
		if($a[0]=='user_id'){
			$post['intID'] = $a['1'];
		}
		$getPoints = $this->points_class->get_points_via_share($post);
		if($getPoints!=0){
			$data['intPoints']=$getPoints['intPoints'];
		}
		echo json_encode($data);
	}
	public function get_earn_points(){
		$post = $this->input->post();
		$a = @split('%3D', @base64_decode($post['intID']));
		if($a[0]=='user_id'){
			$post['intID'] = $a['1'];
		}
		$getPoints = $this->points_class->get_earn_points($post);
		if($getPoints!=0){
			$data['intEarn']=$getPoints['intEarn'];
		}
		echo json_encode($data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */